package org.paradise.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.paradise.dao.JiluDao;
import org.paradise.dao.PackageDao;
import org.paradise.dao.ViprecrdDao;
import org.paradise.pojo.Jilu;
import org.paradise.pojo.Vip;
import org.paradise.pojo.VipRecrd;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/jilu")
public class VipRecrdController {
    @Autowired
    private ViprecrdDao viprecrdDao;
    @Autowired
    private JiluDao jiluDao;
    @Autowired
    private PackageDao packageDao;
    @RequestMapping("/list")
    @ResponseBody
    public Map<String,Object> list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit, VipRecrd vipRecrd) throws Exception{
        Map<String,Object> map=new HashMap<>();
        Page<VipRecrd> pager= PageHelper.startPage(page,limit);
        List<VipRecrd> list=viprecrdDao.getList(vipRecrd);
        map.put("code",0);
        map.put("msg",null);
        map.put("data",list);
        map.put("count",pager.getTotal());
        return map;
    }
    @RequestMapping("/seach")
    @ResponseBody
    public List<Jilu> seach() throws Exception{
        return jiluDao.getAll();
    }
    @RequestMapping("/batchDelete")
    @ResponseBody
    public Map<String,Object> batchDelete(Integer[] ids) throws Exception{
        Map<String,Object> map = new HashMap<>();
        viprecrdDao.batchDelete(ids);
        map.put("result",true);
        return map;
    }
    @RequestMapping("/rolePers")
    @ResponseBody
    public List<Long> rolePers(Integer id)throws Exception{
        return packageDao.getPerIdsByRoleId(id);
    }

}
